package net.ujacha.sadari.multi;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.RandomUtils;

public class Paper {

	public static final int STATUS_READY = 0; // 준비중, 입장 불가, 결과 지정 후 오픈 가능
	public static final int STATUS_OPENED = 1; // 오픈, 입장 가능
	public static final int STATUS_MAKED = 2; // 사다리 모델 생성 확정, 입장 불가, 결과 보기
	public static final int STATUS_CLOSED = 3; // 종료, 입장 불가, 결과보기

	private String id;
	private String name;
	private Date startTime;
	private String leaderId;
	private int status;
	private int maxUser;
	private int line;
	private List<User> users;
	private User[] orders;
	private Goal[] goals;

	private int[][] model;
	private int realGoalNumber;
	private int boomLine;

	private boolean soloMode;
	private boolean oneGoal;

	public Paper(String id, String name, String leaderId, int maxUser, int line, boolean soloMode, boolean oneGoal) {

		this.leaderId = leaderId;
		this.id = id;
		this.name = name;
		this.maxUser = maxUser;
		this.line = line;
		this.soloMode = soloMode;
		this.oneGoal = oneGoal;
		this.status = STATUS_READY;
		this.startTime = new Date();
		this.users = new ArrayList<User>(maxUser);
		this.goals = new Goal[maxUser];
		this.orders = new User[maxUser];

		this.realGoalNumber = RandomUtils.nextInt(0, this.maxUser);
		this.boomLine = RandomUtils.nextInt(3, line);

	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLeaderId() {
		return leaderId;
	}

	public void setLeaderId(String leaderId) {
		this.leaderId = leaderId;
	}

	public int getMaxUser() {
		return maxUser;
	}

	public void setMaxUser(int maxUser) {
		this.maxUser = maxUser;
	}

	public int getLine() {
		return line;
	}

	public void setLine(int line) {
		this.line = line;
	}

	public void addUser(User user) {
		if (!users.contains(user)) {
			users.add(user);
		}
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public Goal[] getGoals() {
		return goals;
	}

	public void setGoals(Goal[] goals) {
		this.goals = goals;
	}

	public boolean setGoal(Goal goal, int order) {
		if (order < goals.length) {
			this.goals[order] = goal;
			return true;
		}
		return false;
	}

	public User[] getOrders() {
		return orders;
	}

	public void setOrders(User[] orders) {
		this.orders = orders;
	}

	public boolean setOrder(User user, int order) {

		boolean b = false;

		if (orders[order] == null) {
			orders[order] = user;
			b = true;
		}
		return b;
	}

	public int[][] getModel() {
		return model;
	}

	public void setModel(int[][] model) {
		this.model = model;

	}

	public boolean isSoloMode() {
		return soloMode;
	}

	public void setSoloMode(boolean soloMode) {
		this.soloMode = soloMode;
	}

	public boolean isOneGoal() {
		return oneGoal;
	}

	public void setOneGoal(boolean oneGoal) {
		this.oneGoal = oneGoal;
	}

	public int getRealGoalNumber() {
		return realGoalNumber;
	}

	public void setRealGoalNumber(int realGoalNumber) {
		this.realGoalNumber = realGoalNumber;
	}

	public int getBoomLine() {
		return boomLine;
	}

	public void setBoomLine(int boomLine) {
		this.boomLine = boomLine;
	}

}
